package br.edu.com1263.action;

import java.util.Map;

import br.edu.com1263.model.Aluno;
import br.edu.com1263.model.Professor;
import br.edu.com1263.negocio.AlunoFacade;
import br.edu.com1263.negocio.ProfessorFacade;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public abstract class MainAction extends ActionSupport {

	private static final long serialVersionUID = -7119393297495920491L;
	
	@SuppressWarnings("unchecked")
	protected Professor recuperarProfessorAtualizado()
	{
		if (getProfessorFacade() == null)
			return null;
		Map<Object, Object> session = ActionContext.getContext().getSession();
		Professor professor = (Professor) session.get("professor");
		if (professor == null)
			return null;
		return getProfessorFacade().consultar(professor.getId());
	}
	@SuppressWarnings("unchecked")
	protected Aluno recuperarAlunoAtualizado()
	{
		Map<Object, Object> session = ActionContext.getContext().getSession();
		Aluno aluno = (Aluno) session.get("aluno");
		if (aluno == null)
			return null;
		return getAlunoFacade().consultar(aluno.getId());
	}
	
	abstract ProfessorFacade getProfessorFacade();
	abstract AlunoFacade getAlunoFacade();
}
